package com.fjwt.gz.proxy.ctrl.award;

import com.alibaba.fastjson2.JSONObject;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.AwardSettingDTO;
import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AwardSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/***
 * 奖品配置 Controller
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/award/setting")
public class AwardSettingController extends CommonCtrl {

    @Autowired
    private AwardSettingService awardSettingService;

    /**
     * 奖品配置新增
     * @return
     */
    @PostMapping("/add")
    public ApiRes add(){
        AwardSettingDTO awardSettingDTO = getObject(AwardSettingDTO.class);
        log.info("机构端奖品配置新增，请求地址：/api/award/setting/add，请求参数：{}", JSONObject.toJSONString(awardSettingDTO));
        return ApiRes.ok(awardSettingService.add(awardSettingDTO));
    }

    /**
     * 奖品配置修改
     * @return
     */
    @PostMapping("/update")
    public ApiRes update(){
        AwardSettingDTO awardSettingDTO = getObject(AwardSettingDTO.class);
        log.info("机构端奖品配置修改，请求地址：/api/award/setting/update，请求参数：{}", JSONObject.toJSONString(awardSettingDTO));
        awardSettingService.update(awardSettingDTO);
        return ApiRes.ok();
    }

    /**
     * 奖品配置详情查询
     * @return
     */
    @GetMapping("/detail")
    public ApiRes detail(){
        AwardSettingDTO awardSettingDTO = getObject(AwardSettingDTO.class);
        log.info("机构端奖品配置查询，请求地址：/api/award/setting/detail，请求参数：{}", JSONObject.toJSONString(awardSettingDTO));
        return ApiRes.ok(awardSettingService.detail(awardSettingDTO));
    }

    /**
     * 更新是否限制可派发人员
     * @return
     */
//    @PreAuthorize("hasAnyAuthority('ENT_COUPON_INFO_EDIT')")
    @PostMapping("/updateIsAllocationUser")
    public ApiRes updateIsAllocationUser(){
        Long awardId = getValLong("awardId");
        Integer isAllocationUser = getValInteger("isAllocationUser");
        Integer awardType = getValInteger("awardType");
        log.info("机构端更新是否限制可派发人员，请求地址：/api/award/setting/updateIsAllocationUser，请求参数：awardId:{}，isAllocationUser：{}，awardType：{}", awardId, isAllocationUser, awardType);
        awardSettingService.updateIsAllocationUser(awardId, isAllocationUser, awardType);
        return ApiRes.ok();
    }


    /**
     * 更新是否限制可派发机构
     * @return
     */
    @PostMapping("/updateIsAllocation")
    public ApiRes updateIsAllocation(){
        Long awardId = getValLong("awardId");
        Integer isAllocation = getValInteger("isAllocation");
        Integer awardType = getValInteger("awardType");
        log.info("机构端更新是否限制可派发机构，请求地址：/api/award/setting/updateIsAllocation，请求参数：awardId:{}，isAllocation：{}，awardType：{}", awardId, isAllocation, awardType);
        awardSettingService.updateIsAllocation(awardId, isAllocation, awardType);
        return ApiRes.ok();
    }
}

